package com.turnengine.client.local.unit.bean;

import com.javabi.common.io.data.IDataReader;
import com.javabi.common.io.data.IDataWriter;
import java.io.IOException;

/**
 * The Unit Count Serializer.
 */
public class UnitCountSerializer implements IUnitCountSerializer {

	@Override
	public IUnitCount readObject(IDataReader reader) throws IOException {

		// Read fields
		int id = reader.readPositiveInt();
		long amount = reader.readPositiveLong();

		// Create object
		IUnitCount object = new UnitCount();
		object.setId(id);
		object.setAmount(amount);
		return object;
	}

	public void writeObject(IDataWriter writer, IUnitCount object) throws IOException {

		// Get fields
		int id = object.getId();
		long amount = object.getAmount();

		// Write fields
		writer.writePositiveInt(id);
		writer.writePositiveLong(amount);
	}
}
